package org.water.garden.view;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class IconTextAdapter extends SimpleAdapter {

	protected String[] from;
	
	public IconTextAdapter(Context context, List data, int resource, String[] from) {
		super(context, data, resource, from, new int[0]);
		this.from = from;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout ll = (LinearLayout) super.getView(position, convertView, parent);
		
		ImageView icon = (ImageView)ll.getChildAt(0);
		TextView text = (TextView)ll.getChildAt(1);
		
		Map data = (Map)getItem(position);
		text.setText(data.get(from[1]).toString());
		icon.setImageResource((Integer)data.get(from[0]));
		
		return ll;
	}

}
